package com.classicInterview;

/**
 * @Author: huangzhigao
 * @Date: 2023/5/7 17:21
 */
public class Code121 {
    public int maxProfit(int[] prices) {
        int sell = 0;
        int buy = 0;
        for (int i = 0; i < prices.length; i++) {
            if (i == 0) {
                sell = 0;
                buy = -prices[i];
            } else {
                sell = Math.max(sell, buy + prices[i]);
                buy = Math.max(buy, -prices[i]);
            }
        }
        return sell;
    }
}
